package uk.ac.lkl.common.util.ds.event;



import java.util.EventObject;
import java.util.Map;


/**
 * For entryAdded: <oldKey, oldValue, newKey, newValue> = <null, null,
 * K, V> For entryRemoved: <K, V, null, null> For valueChanged: <K,
 * V1, K, V2>
 * 
 * @author Darren Pearce
 * @version $Revision$
 * @version $Date$
 * 
 */
public class MapEvent<K, V> extends EventObject {

    private K oldKey;

    private V oldValue;

    private K newKey;

    private V newValue;


    private MapEvent(
                     Map<K, V> map, K oldKey, V oldValue, K newKey, V newValue) {
        super(map);
        this.oldKey = oldKey;
        this.oldValue = oldValue;
        this.newKey = newKey;
        this.newValue = newValue;
    }


    public static <K, V> MapEvent<K, V> createEntryAddedEvent(Map<K, V> map,
                                                              K key,
                                                              V value) {
        return new MapEvent<K, V>(map, null, null, key, value);
    }


    public static <K, V> MapEvent<K, V> createEntryRemovedEvent(Map<K, V> map,
                                                                K key,
                                                                V value) {
        return new MapEvent<K, V>(map, key, value, null, null);
    }


    public static <K, V> MapEvent<K, V> createValueChangedEvent(Map<K, V> map,
                                                                K key,
                                                                V oldValue,
                                                                V newValue) {
        return new MapEvent<K, V>(map, key, oldValue, key, newValue);
    }


    public K getOldKey() {
        return oldKey;
    }


    public K getKey() {
        return newKey;
    }


    public K getNewKey() {
        return newKey;
    }


    public V getOldValue() {
        return oldValue;
    }


    public V getValue() {
        return newValue;
    }


    public V getNewValue() {
        return newValue;
    }


    public Map<K, V> getMap() {
        return (Map<K, V>) getSource();
    }

}
